package com.esri.core.tasks.tilecache;

import com.esri.core.internal.util.d;
import com.esri.core.io.EsriServiceException;
import com.esri.core.io.UserCredentials;
import com.esri.core.tasks.ags.geoprocessing.GPGetJobResultParameters;
import com.esri.core.tasks.ags.geoprocessing.GPGetJobResultTask;
import com.esri.core.tasks.ags.geoprocessing.GPJobResource;
import com.esri.core.tasks.ags.geoprocessing.GPString;
import java.util.ArrayList;
import java.util.Iterator;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParser;

/* loaded from: classes.dex */
public class TileCacheJobResource {
    private Exception mException;
    private GPJobResource mGpJobResource;
    private String mItemId;
    private String mJobID;
    private GPJobResource.JobStatus mJobStatus;
    private ArrayList<String> mResultUrls = new ArrayList<>();
    private boolean mIsOnlineTileCache = false;

    public TileCacheJobResource(Exception exc) {
        this.mException = exc;
    }

    public TileCacheJobResource() {
    }

    public static TileCacheJobResource fromJson(JsonParser jsonParser, String str, UserCredentials userCredentials) throws Exception {
        if (!d.c(jsonParser)) {
            throw new EsriServiceException("Unable to parse the Response for this TileCacheJobResource.");
        }
        TileCacheJobResource tileCacheJobResource = new TileCacheJobResource();
        JsonNode b = d.b(jsonParser);
        tileCacheJobResource.mJobID = b.get("jobId").asText();
        tileCacheJobResource.mJobStatus = GPJobResource.JobStatus.fromString(b.get("jobStatus").asText());
        JsonNode jsonNode = b.get("output");
        if (jsonNode != null && !jsonNode.isNull()) {
            tileCacheJobResource.mIsOnlineTileCache = true;
            tileCacheJobResource.mItemId = jsonNode.get("itemId").asText();
            Iterator<JsonNode> elements = jsonNode.get("outputUrl").getElements();
            while (elements.hasNext()) {
                tileCacheJobResource.mResultUrls.add(elements.next().asText());
            }
        }
        if (!tileCacheJobResource.mIsOnlineTileCache) {
            tileCacheJobResource.mGpJobResource = GPJobResource.fromJson(d.c(b.toString()));
        }
        if (tileCacheJobResource.mGpJobResource != null) {
            tileCacheJobResource.getUrlFromGpJobResource(str, userCredentials);
        }
        return tileCacheJobResource;
    }

    public GPJobResource.JobStatus getJobStatus() {
        return this.mJobStatus;
    }

    public String getResultUrl() {
        return !this.mResultUrls.isEmpty() ? this.mResultUrls.get(0) : "";
    }

    public String getJobID() {
        return this.mJobID;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean isOnlineTileCache() {
        return this.mIsOnlineTileCache;
    }

    public GPJobResource getGPJobResource() {
        return this.mGpJobResource;
    }

    public Exception getException() {
        return this.mException;
    }

    private void getUrlFromGpJobResource(String str, UserCredentials userCredentials) {
        if (GPJobResource.JobStatus.SUCCEEDED.equals(this.mJobStatus)) {
            GPGetJobResultParameters gPGetJobResultParameters = new GPGetJobResultParameters(this.mGpJobResource, "out_service_url", false);
            try {
                this.mResultUrls.add(((GPString) new GPGetJobResultTask(gPGetJobResultParameters, str + "/exportTiles", userCredentials).execute()).getValue());
            } catch (Exception e) {
                this.mException = e;
            }
        }
    }
}
